package com.feiniu.api.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesUtil.class);

    private PropertiesUtil() {
    }

    private static class SingletonHolder {
        private static final PropertiesUtil INSTANCE = new PropertiesUtil();

        private SingletonHolder() {
        }
    }

    public static PropertiesUtil getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public Properties getProperties(String file) {
        Properties properties = new Properties();
        InputStream inputStream = null;
        try {
            inputStream = PropertiesUtil.class.getClassLoader()
                    .getResourceAsStream(file);
            properties.load(inputStream);
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    LOGGER.error(e.getMessage(), e);
                }
            }
        }
        return properties;
    }

}
